package com.utils

import android.content.Context
import android.widget.RelativeLayout


object UIUtils {
    /**
     * 获取Image图片的宽高
     *
     * @param context
     * @param count
     * @param scale
     * @param left
     * @return
     */
    fun getImageParams(
        context: Context,
        count: Int, scale: Double, margins: Float
    ): RelativeLayout.LayoutParams {
        //获取当前显示的界面大小
        val dm = context.resources.displayMetrics
        val w = dm.widthPixels //获取当前界面的宽度
        val imageWidth = w / count //得到屏幕宽度的一半
        val imageHeight = (imageWidth * scale).toInt()
        //       int imageHeight = w / count;

        //定义好控件的属性即把屏幕宽度的一半设置成imageview的宽高。LinearLayout表示 iv_hot_item 外层布局
//        LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(imageWidth, imageHeight);
        val imageParams = RelativeLayout.LayoutParams(imageWidth, imageHeight)
        imageParams.setMargins(
            DensityUtils.dp2px(context, margins),
            DensityUtils.dp2px(context, margins),
            DensityUtils.dp2px(context, margins),
            DensityUtils.dp2px(context, margins)
        )
        imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL) //添加水平居中
        return imageParams
    }
}